import logging
import os
from datetime import datetime
from config.config import LOG_CONFIG


def setup_logger():
    """配置日志"""
    # 创建日志目录
    log_dir = os.path.dirname(LOG_CONFIG['file'])
    if not os.path.exists(log_dir):
        os.makedirs(log_dir)

    # 配置日志
    logging.basicConfig(
        level=LOG_CONFIG['level'],
        format=LOG_CONFIG['format'],
        handlers=[
            logging.FileHandler(LOG_CONFIG['file']),
            logging.StreamHandler()
        ]
    )


def get_timestamp():
    """获取当前时间戳"""
    return datetime.now().strftime("%Y%m%d_%H%M%S")